package com.example.safeassistan.my.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.safeassistan.R;
import com.example.safeassistan.base.BaseActivity;
import com.example.safeassistan.common.UserData;

public class ActivityPhone  extends BaseActivity implements View.OnClickListener {
    TextView tvChangePhone,tvCurrentPhone;


    public static void actionStart(Context context) {
        Intent intent = new Intent(context, ActivityPhone.class);
        context.startActivity(intent);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tvChangePhone:
                //更改手机号
                if (UserData.create(ActivityPhone.this).get(UserData.PHONE)!=null&&!UserData.create(ActivityPhone.this).get(UserData.PHONE).equals("")){
                    ActivityBindPhone.actionStart(getContext(),0);
                }else {
                    ActivityBindPhone.actionStart(getContext(),1);
                }

                break;
        }
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_phone;
    }

    @Override
    protected void initView() {
        setTitleText("手机号");
        tvCurrentPhone=findViewById(R.id.tvCurrentPhone);
        tvChangePhone=findViewById(R.id.tvChangePhone);
        tvChangePhone.setOnClickListener(this::onClick);



    }

    @Override
    protected void initData() {
        if (UserData.create(ActivityPhone.this).get(UserData.PHONE)!=null&&!UserData.create(ActivityPhone.this).get(UserData.PHONE).equals("")){
            String p=UserData.create(ActivityPhone.this).get(UserData.PHONE).substring(0,3)+"****"+UserData.create(ActivityPhone.this).get(UserData.PHONE).substring(7,11);
            tvCurrentPhone.setText("当前手机号码："+p);
            tvChangePhone.setText("更改手机号码");
        }else {
            tvCurrentPhone.setText("当前暂未设置手机号");
            tvChangePhone.setText("绑定手机号码");
        }
    }

    @Override
    protected int getTitleBarType() {
        return 0;
    }
}
